package com.example.demo.seven;

import com.example.demo.util.RabbitMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;

/**
 * @author chensixiang chensixiang1234@gmail.com
 */
public class ReceiveLogsTop01 {
    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);

        String queue = "Q1";
        channel.queueDeclare(queue, false, false, false, null);

        channel.queueBind(queue, EXCHANGE_NAME, "*.orange.*");
        System.out.println("C1等待接受消息......");

        channel.basicConsume(queue, true, (consumerTag, message) -> {
            System.out.println("消息为 -> " + new String(message.getBody()));
            System.out.println("绑定键 -> " + message.getEnvelope().getRoutingKey());
        }, (consumerTag, sig) -> {
        });
    }
}
